﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLib.Gameplay.Scripting;
using GameLib.Gameplay.Plots;
using GameLib.Gameplay.Stories;
using GameLib.Main;
using GameLib.Gameplay.Global;
using GameLib.Serialization;

namespace GameLib.Gameplay
{
	public class Play
	{

		public virtual void Update(double deltaTime)
		{
			throw new System.NotImplementedException();
		}

		public static Play New(string playDataPath)
		{
			Play play = new Play();
			Core.Play = play;
			Core.DataHandler.Read(play, playDataPath);
			return play;
		}

		public static Play Load(string savedFilePath)
		{
			throw new System.NotImplementedException();
		}

		public static void Save(Play play, string savedFilePath)
		{
			throw new System.NotImplementedException();
		}

		public void Begin()
		{
			ActivatePlot(new MainPlot());
			PlayEvent_NewPlayStarted();

		}
		
		public void ActivatePlot(Plot plot)
		{
			m_ActivePlots.Add(plot);
			plot.OnActivated(this);
		}

		public ScriptList ScriptList
		{
			get;
			private set;
		}

		public Scene CurrentScene
		{
			get { return Protagonist.Scene; }
		}

		public Player Protagonist
		{
			get;
			private set;
		}

		public StoryManager StoryManager
		{
			get;
			private set;
		}

		public World World
		{
			get;
			private set;
		}

		#region Play Events

		private void PlayEvent_NewPlayStarted()
		{
			foreach (Plot plot in m_ActivePlots)
			{
				plot.PlayEvent_NewPlayStarted();
			}
		}

		#endregion

		private Play()
		{
			World = new World();
			StoryManager = new StoryManager();
			StoryManager.StoryBegin += new StoryEventHandler(OnStoryBegin);
			StoryManager.StoryEnd += new StoryEventHandler(OnStoryEnd);
		}


		void OnStoryBegin()
		{
		}

		void OnStoryEnd()
		{
		}



		private List<Plot> m_ActivePlots = new List<Plot>();
	}
}
